package com.cskaoyan.service;

import com.cskaoyan.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author stone
 * @date 2021/12/29 09:51
 */
@Service
public class AccountServiceImpl implements AccountService{
    @Autowired
    AccountMapper accountMapper;

    @Override
    public void transfer(Integer fromId, Integer destId, Integer money) {
        //原始money
        Integer fromMoney = accountMapper.selectMoneyById(fromId);
        Integer destMoney = accountMapper.selectMoneyById(destId);
        //计算转账后的money
        fromMoney -= money;
        destMoney += money;
        //执行更新，更新转账后的money
        accountMapper.update(fromId, fromMoney); //事务提交了
        int i = 1 / 0;  //发生异常
        accountMapper.update(destId, destMoney); //没有执行到
    }
}
